﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using XNAGuiLib.Core.Graphics;

namespace XNAGuiLib.Core.Resources
{
    public class Image : GIComponent
    {

        public Image(Game game, int width, int height, string imageFile)
            : base(game)
        {
            this._width = width;
            this._height = height;

            Texture2D tx_test = Texture2DLoader.LoadT2D(game.GraphicsDevice, imageFile);
            this.Add(new ContentComponent(tx_test, new Rectangle(0, 0, this._width, this._height)));
        }

        public void LoadImage(string imageFile)
        {
            Texture2D tx_test = Texture2DLoader.LoadT2D(this._game.GraphicsDevice, imageFile);
            this._content[0].ContTexture.Value = tx_test;
            this.UpdateSize();
        }

        // Virtual Method - Resize(int width, int height)
        #region Image Protected Virtual Method - Resize(int width, int height)
        protected override void Resize(int width, int height)
        {
            this._width = width;
            this._height = height;
            this._content[0].ContTexture.Rectangle = new Rectangle(0, 0, width, height);
        }
        #endregion
    }
}